# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:newdate1_0.py
@Time:2024/12/4 15:34

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""
import csv
from datetime import datetime,timedelta

# 函数用于解析日期字符串
def parse_date(date_str):
    return datetime.strptime(date_str, '%Y%m%d')

# 函数用于找到最新的日期
def find_latest_date(csv_file):
    latest_date = None
    with open(csv_file, mode='r', encoding='utf-8') as file:
        reader = csv.DictReader(file)
        for row in reader:
            current_date = parse_date(row['日期'])
            if latest_date is None or current_date > latest_date:
                latest_date = current_date
    return (latest_date+timedelta(days=1)).strftime('%Y%m%d')

# CSV文件路径
csv_file_path = '../news/outputnews_2024.csv'

if __name__ == "__main__":
    # 获取并打印最新的日期
    latest_date = find_latest_date(csv_file_path)
    print(latest_date)
    print(type(latest_date))
    # print(latest_date.strftime('%Y%m%d'))
    # print(type(latest_date.strftime('%Y-%m-%d')))
    # if latest_date:
    #     print("最新的日期是:", latest_date.strftime('%Y-%m-%d'))
    # else:
    #     print("没有找到日期记录。")